﻿using System;
using System.Windows.Input;

namespace NanoMvvm
{
    public class CommandSelectionItemViewModel<T> : SelectionItemViewModel<CommandViewModel<T>>
        where T : CommandBase
    {
        internal CommandSelectionItemViewModel(SelectionViewModel<CommandViewModel<T>> parent, CommandViewModel<T> item)
            : base(parent, item)
        {
            item.Command.CanExecuteCondition = () => IsSelectable;

            ((ICommand)item.Command).CanExecuteChanged += (sender, args) => IsSelectable = ((ICommand)item.Command).CanExecute(null);
        }
    }
}